import React, { Suspense } from 'react';
import { useSelector } from 'react-redux';
import { Result } from 'antd';



function Authority(props) {
    //获取store中的用户权限列表
    var checkedkeys = useSelector((state) => state.userInfo.checkedkeys);
    //判断当前组件的权限标识是否存在于权限列表中
    var res = checkedkeys?.length == 0 || checkedkeys?.includes(props.permission)
    return (
        <Suspense fallback={<div>Loading...</div>}>
            {res ? props.children : <Result status="403" title="403" subTitle="Sorry, you are not authorized to access this page." />}
        </Suspense>
    );
}

export default Authority;